<?php 
namespace app\admin\controller;

use think\Controller;
use app\model\Category;

class Categorydo extends Controller{

	// 查看分类列表
	public function getCategoryList(){
		$categorys = Category::getListByPage(10);
		$this->assign("categorys",$categorys);
		return $this->fetch();
	}

	// 添加分类
	public function addCategory(){
		$pars["category_id"] = getId();
		$pars["category_name"] = input("category_name");
		$category = Category::create($pars);
		return getResponse(0,$category);
	}

	// 修改分类
	public function editCategory(){
		$category = Category::get(input("category_id"));
		$category->category_name = input("editName");
		$category->save();
		return getResponse(0,"修改成功");
	}

	// 启用用户
	public function doCategoryEnable(){
		$category = Category::get(input("category_id"));
		$category->is_delete = 0;
		$category->save();
		return getResponse(0,$category);
	}

	// 禁用分类
	public function doCategoryDisable(){
		$num = Category::getCommodityNum(input("category_id"));
		if($num == 0){
			$category = Category::get(input("category_id"));
			$category->is_delete = 1;
			$category->save();
			return getResponse(0,$category);
		}
		return getResponse(1,"该分类下有商品，无法禁用！");
	}
}


 ?>